// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "logsimpl.h"
#include "logdatabase.h"
#include "logfilters.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}



static_const STDCOM_OBJMAP_ENTRY ComClassObject[] =
{
	{CLSID_STDCOM_ClassFactory,
	&CoComFactoryCreator<CNullObjcetUnkown>::GetClassObject,
	"Plugin.Factory.impl.V1"},

	{CLSID_ILogs,
	&CoComFactoryCreator<CLogsImpl>::GetClassObject,
	"Logs.impl.V1" },

	{CLSID_ILogDataBase,
	&CoComFactoryCreator<CLogDataBaseImpl>::GetClassObject,
	"LogDataBase.impl.V1" },

	{ CLSID_ILogFilters,
	&CoComFactoryCreator<CLogFiltersImpl>::GetClassObject,
	"LogFilters.impl.V1" }

};

static_const STDCOM_OBJMAP_ENTRY* GetClassObjectMap()
{
	return ComClassObject;
}

static_const long  GetClassObjectMapSize()
{
	return sizeof(ComClassObject) / sizeof(ComClassObject[0]);
}

std_com_export DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv)
{
	size_t i = 0;
	for (i = 0; i < sizeof(ComClassObject) / sizeof(ComClassObject[0]); ++i)
	{
		if (rclsid == ComClassObject[i].clsid)
		{
			return ComClassObject[i].pfnGetClassObject(riid, ppv);
		}
	}
	return E_INVALIDARG;
}
_stdmethod_export(CLSID, DllGetAt)(LONG nIndex)
{
	const STDCOM_OBJMAP_ENTRY* pMap = GetClassObjectMap();
	return pMap[nIndex + 1].clsid;
}
_stdmethod_export(LONG, DllGetCount)()
{
	const long lCount = GetClassObjectMapSize();
	return (lCount > 0) ? lCount - 1 : 0;
}
_stdmethod_export(LPCSTR, DllProgIDFromCLSID)(REFCLSID clsid)
{
	const STDCOM_OBJMAP_ENTRY* pMap = GetClassObjectMap();
	long i = 1;
	for (i = 1; i < GetClassObjectMapSize(); ++i)
	{
		if (clsid == pMap[i].clsid)
		{
			return pMap[i].ProgID;
		}
	}
	return "";
}
std_com_export DllCanUnloadNow(void)
{
	return S_OK;
}
std_com_export DllRegisterServer(void)
{
	return S_OK;
}
std_com_export DllUnregisterServer(void)
{
	return S_OK;
}
std_com_export DllStartServer(void)
{
	return S_OK;
}
std_com_export DllStopServer(void)
{
	return S_OK;
}
